<?php

/**
 * Remove an user.
 */
class sfGuardRemoveUserTask extends sfBaseTask
{
	
  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('username', sfCommandArgument::REQUIRED, 'The username'),
      new sfCommandArgument('application', sfCommandArgument::OPTIONAL, 'The application name','ui')
    ));


    $this->namespace = 'guard';
    $this->name = 'remove-user';
    $this->briefDescription = 'Removes an user';

    $this->detailedDescription = <<<EOF
The [guard:remove-user|INFO] task removes a user:

  [./symfony guard:remove-user username|INFO]
EOF;
  }

  /**
   * @see sfTask
   */
  protected function execute($arguments = array(), $options = array())
  {
	$databaseManager = new sfDatabaseManager($this->configuration);
	$this->log("Deleting ".$arguments['username']);
    if(!LdapLogin::removeUser($arguments['username']))
        throw new Exception('User does not exists in LDAP database');
    
    $user = Doctrine::getTable("sfGuardUser")->findByUsername($arguments['username'])->getFirst();
	$user->delete();
	$this->log("User removed");
    

  }
  
}